<template>
	<view class="content">
		<view class="loginFrame">
			<view class="loginStore" style="border: 1rpx red solid;">
				<view class="loginFont">账号：</view>
				<input class="inputUser" v-model="userName" type="text" placeholder="请输入用户名"
					placeholder-class="placeholder">
				<view class="loginFont" style="margin-top: 15rpx;">密码：</view>
				<input class="inputUser" v-model="passWord" type="password" placeholder="请输入密码"
					placeholder-class="placeholder">
				<view class="toHappy" @click="toHappy()">立即登录</view>
				<view class="toHappy" @click="toTest()">ceshiceshi</view>
				<view class="loginMonth">——— 使用以下方式登录 ———</view>
				<view class="wxOut" @click="toOrder()">
					<image class="wxLogin" src="../../static/wx.png"></image>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import common from "../../common/common.js"

	export default {
		data() {
			return {
				userName: '',
				passWord: '',
				url: 'http://192.168.10.11:8035/im/text/104eac.html',
				tableNum: 7, //餐桌号
				dinerNum: 2, //用餐人数
			}
		},
		onLoad() {
			this.toWxHappy();
		},
		methods: {
			gogo() {
				uni.navigateTo({
					url:"/pages/login/ceshia"
				})
			},
			toTest(){
				uni.navigateTo({
					url:"/pages/index/chatTest/chatTest"
				})
			},
			
			toHappy() {
				uni.showLoading({
					title: "加载中",
					mask: true
				});
				uni.request({
					url: 'http://localhost:8080/wxLogin',
					data: {
						username: this.userName,
						password: this.passWord
					},
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						if (res.data.code == 200) {
							uni.setStorageSync('token', res.data.token);
							// uni.navigateTo({
							// 	url:'/pages/index/index'
							// })
						} else {
							uni.showToast({
								title: res.data.code + '：' + res.data.msg,
								icon: 'none',
								duration: 2000
							})
						}

					}
				});
				uni.hideLoading();
			},
			toWxHappy() {
				console.log("微信登录");
				wx.login({
					success(res) {
						uni.request({
							url: 'http://43.138.22.133:8080/wxLogin',
							data: {
								code: res.code
							},
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded'
							},
							success: function(res) {
								if (res.data.code == 200) {
									uni.setStorageSync('token', res.data.token);
									console.log("登录成功，已存储token：", uni.getStorageSync('token'));
									uni.switchTab({
										url: '/pages/index/index'
									})
								} else {
									uni.showToast({
										title: res.data.state + '：' + res.data.message,
										icon: 'none',
										duration: 2000
									})
								}
							}
						})
					}
				})
			},
			//去点餐
			toOrder() {
				common.post({
					url: '/orderEat/orderInfo/addTableAndUser',
					formData: {
						tableId: this.tableNum
					},
					success: (res) => {
						console.log("存储餐桌号");
					}
				})
				uni.navigateTo({
					url: '/pages/index/index?tableNum=' + this.tableNum + '&dinerNum=' + this.dinerNum
				})
			}

		}
	}
</script>

<style>
	.content {
		width: 100%;
		height: 100vh;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.loginFrame {
		width: 80%;
		height: 40%;
		background-color: rgba(255, 255, 255, 0.7);
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.loginStore {
		width: 90%;
		height: 90%;

	}

	.inputUser {
		border-bottom: 1px darkgray solid;
		font-size: 30rpx;
		margin-left: 15rpx;
		margin-top: 10rpx;
	}

	.loginFont {
		font-size: 30rpx;
		margin-left: 10rpx;
	}

	.toHappy {
		width: 100%;
		height: 60rpx;
		margin-top: 20rpx;
		border-radius: 16rpx;
		background-color: #1989FA;
		color: #fff;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.wxOut {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 150rpx;
	}

	.wxLogin {
		width: 80rpx;
		height: 80rpx;
	}
</style>